﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.SqlClient;
using System.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Data;
using AppInterface;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace AppInterface.[tblName]
{

	//[tblName].[tblName]Manage [tblName] = new [tblName].[tblName]Manage();
	//container.Add("[tblName]List".ToLower(), new InterfacePro([tblName].List, false, 0));//列表
	//container.Add("[tblName]Add".ToLower(), new InterfacePro([tblName].Add, false, 0));//添加
	//container.Add("[tblName]Update".ToLower(), new InterfacePro([tblName].Update, false, 0));//修改

    public class [tblName]Manage :BaseClass
    {
        public Bll.[tblName]Bll bll = new Bll.[tblName]Bll();
        public Msg_Result List(System.Web.HttpContext context, ParamData param)
        {
            int pageindex = GetIntParam(context, "pageindex");
            int pagecount = GetIntParam(context, "pagecount");

            Dictionary<string, string> dicCondition = new Dictionary<string, string>();
            //输入参数
			[loop start]
            //dicCondition.Add("[fldName]", GetStringParam(context, "[fldName]"));//按[fldTitle] 进行查询
             [loop end]^

            var dset = bll.GetDataset(dicCondition);
            return PageMsg(param.Action, dset, pageindex, pagecount);
        }

        public Msg_Result Add(System.Web.HttpContext context, ParamData param)
        {
			^[loop start]
            string [fldName] = GetString("[fldName]");
             [loop end]^

             var m{tblName} = new Data.[tblName]();
			^[loop start]
             //m{tblName}.[fldName] = [fldName];	//[fldTitle]
             [loop end]^
            if (bll.Add(m{tblName}))
            {
                return NoPageMsg(param.Action, m{tblName});
            }
            else
            {
                return ErrMsg(param.Action, "添加失败");
            }

        }
        public Msg_Result Update(System.Web.HttpContext context, ParamData param)
        {
            int id = GetIntParam(context, "id");
			^[loop start]
            string [fldName] = GetString("[fldName]");
             [loop end]^

             var m{tblName} = bll.GetById(id);
			^[loop start]
             //m{tblName}.[fldName] = [fldName];	//[fldTitle]
             [loop end]^

            if (bll.Update(m{tblName}))
            {
                return NoPageMsg(param.Action, m{tblName});
            }
            else
            {
                return ErrMsg(param.Action, "修改失败");
            }

        }
       
        public Msg_Result Delete(System.Web.HttpContext context, ParamData param)
        {
            int id = GetIntParam(context, "id");
            if (bll.DeleteById(id))
            {
                return NoneMsg(param.Action);
            }
            else
            {
                return ErrMsg(param.Action, "删除失败");
            }

        }
    }
}


